import initConfig from '../../assets/js/initconfig'
const state = {
  appVersion: 0.1,
  // 全局计数器
  globalCount: 0,
  // 所有图标的配置说明
  chartsConfig: []
}

const mutations = {
  ADD_CHART: (state, chart) => {
    // 添加报表
    state.chartsConfig.push(initConfig[chart]())
  },
  REMOVE_CHART: (state, chartId) => {
    // 移除数据
    state.chartsConfig.splice(state.chartsConfig.findIndex(item => item['chartId'] === chartId), 1)
  },
  RESIZE: (state, layout) => {
    // 调整页面
    state.chartsConfig[layout.index].layout.width = layout.width
    state.chartsConfig[layout.index].layout.height = layout.height
  },
  DRAG: (state, layout) => {
    // 调整位置xy
    state.chartsConfig[layout.index].layout.offsetLeft = layout.x
    state.chartsConfig[layout.index].layout.offsetTop = layout.y
  },
  // 隐藏图表
  HIDE_CHART: (state, {chartId, isVisible}) => {},
  // 显示图表
  SHOW_CHART: (state, chartId) => {}
}

const actions = {
  addChart ({ commit }, chart) {
    commit('ADD_CHART', chart)
  },
  removeChart ({ commit }, chartId) {
    commit('REMOVE_CHART', chartId)
  },
  onResize ({ commit }, layout) {
    commit('RESIZE', layout)
  },
  onDrag ({ commit }, layout) {
    commit('DRAG', layout)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
